<?php

namespace Plugins\Edge\Common\Model;

use App\Common\Model\Attribute\CreateSql;
use App\Common\Model\Model;

/**
 * 新闻资讯
 * @property int    $id          ID
 * @property string $title       标题
 * @property string $intro       简介
 * @property array  $tag         标签
 * @property int    $is_top      置顶
 * @property string $cover       封面
 * @property int    $view_number 浏览数
 * @property string $author      作者
 * @property int    $status      状态
 * @property string $content     内容
 * @property string $create_time 创建事件
 * @property string $update_time 更新时间
 * @property int    $delete_time 删除时间
 */
#[CreateSql(<<<SQL
CREATE TABLE `sc_news` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `title` varchar(128) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '标题',
  `intro` varchar(512) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '简介',
  `tag` json DEFAULT NULL COMMENT '标签',
  `is_top` tinyint(1) NOT NULL DEFAULT '0' COMMENT '置顶：0=否，1=是',
  `cover` varchar(255) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '封面',
  `view_number` int(11) NOT NULL DEFAULT '0' COMMENT '浏览数',
  `author` varchar(12) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '作者',
  `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态：0=下架，1=上架',
  `content` text COLLATE utf8mb4_general_ci NOT NULL COMMENT '内容',
  `create_time` datetime NOT NULL COMMENT '创建事件',
  `update_time` datetime NOT NULL COMMENT '更新时间',
  `delete_time` int(11) DEFAULT NULL COMMENT '删除时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='新闻资讯'
SQL)]
class News extends Model
{

    protected $schema = [
        'id' => 'int',
        'title' => 'varchar',
        'intro' => 'varchar',
        'tag' => 'json',
        'is_top' => 'tinyint',
        'cover' => 'varchar',
        'view_number' => 'int',
        'author' => 'varchar',
        'status' => 'tinyint',
        'content' => 'text',
        'create_time' => 'datetime',
        'update_time' => 'datetime',
        'delete_time' => 'int'
    ];

    protected $type = [
        ...self::DEFAULT_CASTS,
        'tag' => 'array'
        // 更多casts
    ];

    protected $field = ["title", "intro", "tag", "is_top", "cover", "view_number", "author", "status", "content"];

    
}

